package com.xuanyuan.navaction

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.xuanyuan.adapter.JumpGoBean
import com.xuanyuan.adapter.MainListAdapter
import com.xuanyuan.base.utils.ArouterUtils
import com.xuanyuan.base.listener.ItemClickListener
import com.xuanyuan.material.*
import com.xuanyuan.material.databinding.FragmentMaterialBinding

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 * A simple [Fragment] subclass.
 * Use the [Fragment1.newInstance] factory method to
 * create an instance of this fragment.
 */
class FragmentMaterial : Fragment(), View.OnClickListener, ItemClickListener<JumpGoBean> {
    private var param1: String? = null
    private var param2: String? = null
    lateinit var mBinding: FragmentMaterialBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            param1 = it.getString(ARG_PARAM1)
            param2 = it.getString(ARG_PARAM2)
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_material, container, false)
        mBinding.click = this
//        return inflater.inflate(R.layout.fragment_material, container, false)
        initListView()
        return mBinding.root
    }

    private fun initListView() {
        val adapter = MainListAdapter()
        mBinding.recyclerView.adapter = adapter
        adapter.setClickListener(this)
        mBinding.recyclerView.layoutManager = LinearLayoutManager(activity)
        adapter.setList(JumpGoBean.getDataList())

    }

    override fun onClick(view: View?) {
        if (view == null) {
            return
        }


    }


    companion object {
        @JvmStatic
        fun newInstance(param1: String, param2: String) =
            FragmentMaterial().apply {
                arguments = Bundle().apply {
                    putString(ARG_PARAM1, param1)
                    putString(ARG_PARAM2, param2)
                }
            }
    }

    override fun onItemClick(position: Int, t: JumpGoBean) {


        activity?.let {
            ArouterUtils.startActivityCommon(it, t.cls)
        }


    }
}